﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace com.guysherman.simulclass
{
    public static class TypeExtensions
    {
        public static string PrimitiveTypeName(this Type t)
        {
            switch (t.FullName)
            {
                case "System.Boolean":
                    return "bool";
                case "System.Byte":
                    return "uchar";
                case "System.Char":
                    return "wchar";
                case "System.Double":
                    return "double";
                case "System.Int16":
                    return "short";
                case "System.Int32":
                    return "int";
                case "System.Int64":
                    return "long long";
                case "System.SByte":
                    return "char";
                case "System.Single":
                    return "float";
                case "System.UInt16":
                    return "unsigned short";
                case "System.UInt32":
                    return "unsigned int";
                case "System.UInt64":
                    return "unsigned long long";
                case "System.String":
                    return "LPTSTR";
                case "System.Void":
                default:
                    return "void";

            }
        }

        public static string PrimitiveByRefTypeName(this Type t)
        {
            switch (t.FullName)
            {
                case "System.Boolean&":
                    return "bool*";
                case "System.Byte&":
                    return "uchar*";
                case "System.Char&":
                    return "wchar*";
                case "System.Double&":
                    return "double*";
                case "System.Int16&":
                    return "short*";
                case "System.Int32&":
                    return "int*";
                case "System.Int64&":
                    return "long long*";
                case "System.SByte&":
                    return "char*";
                case "System.Single&":
                    return "float*";
                case "System.UInt16&":
                    return "unsigned short*";
                case "System.UInt32&":
                    return "unsigned int*";
                case "System.UInt64&":
                    return "unsigned long long*";
                case "System.String&":
                    return "LPTSTR*";
                case "System.Void&":
                default:
                    return "void*";

            }
        }

        public static string EmbeddedTypeName(this Type t)
        {
            string embeddedTypeName = string.Empty;
            if (t.IsByRef)
            {
               
                string primitiveRefTypeName = t.PrimitiveByRefTypeName();
                if (primitiveRefTypeName == "void*" && t.FullName != "System.Void&")
                {
                    return "MonoObject**";
                }
                else
                {
                    return primitiveRefTypeName;
                }

            }
            else
            {
                if (t.IsPrimitive || t.FullName == "System.String" || t.FullName == "System.Void")
                {
                    return t.PrimitiveTypeName();
                }
                else
                {
                    return "MonoObject*";
                }
            }
        }

    }
}
